<template>
    <NormalTable
        :refresh-action="'盘存查询'"
        :tableColumns="tableColumns"
        :tableAttribute="tableAttribute"
        :show-page="true"
        ref="childRef"
    >
    </NormalTable>
    
    
    
</template>
<script setup lang="ts" name="Inventory">
import { ref, reactive, onMounted } from 'vue';
import { storeToRefs } from 'pinia';
import type { CntrModel } from '@/common/types/container';
import {
    tableColumnDefault
} from '@/hooks/useTable';
import type { QueryItem, TableColumn } from '@/common/types/app';
import { pickQueryFromTable } from '@/common/tools';
import type { TableInstance } from 'element-plus';
import { useAppStore } from '@/store/app';
import { transFormatter, formatDateTime } from '@/common/tools';
import NormalTable from '@/components/tables/NormalTable.vue';
// import UpdateCntr from './UpdateCntr.vue';
const { cntrDam, cyCfs } = storeToRefs(useAppStore());
const tableAttribute = ref({
    id: 'Inventory-table-cntrs',
});
const childRef = ref<InstanceType<typeof NormalTable>>();
const tableRef = ref<TableInstance>();
const tableData = ref<Array<CntrModel>>([]);
const tableHeight = ref(100);
const onFormatter = (_row: any, column: any, cellValue: any) => {
    let data: { value: string | number; label: string }[];
    if (column['property'] === 'dam_id') {
        data = cntrDam.value;
    } else if (column['property'] === 'cfs_cod') {
        data = cyCfs.value;
    } else {
        return cellValue;
    }
    return transFormatter(cellValue, data);
};
const tableColumns = reactive<TableColumn[]>([
    {
        ...tableColumnDefault,
        order: 1,
        prop: 'cntr',
        label: '箱号',
        fixed: 'left',
        sortable: 'custom',
        formFieldItemType: 'input',
        width: 150,
    },
    {
        ...tableColumnDefault,
        order: 2,
        prop: 'cntr_siz_cod',
        fixed: 'left',
        label: '箱尺寸',
        sortable: 'custom',
        width: 80,
    },
    {
        ...tableColumnDefault,
        order: 3,
        fixed: 'left',
        prop: 'cntr_typ_cod',
        label: '箱型',
        sortable: 'custom',
        width: 80,
    },
    /* {
        ...tableColumnDefault,
        order: 9,
        prop: 'stack_days',
        label: '堆存天数',
        sortable: 'custom',
        width: 100,

    }, */
    {
        ...tableColumnDefault,
        order: 4,
        prop: 'cfs_cod',
        label: '站点',
        sortable: 'custom',
        formatter: onFormatter,
        formFieldItemType: 'single',
        optionalValues: cyCfs.value,
        width: 180,
    },
    {
        ...tableColumnDefault,
        order: 5,
        prop: 'to_port_tim',
        label: '进场时间',
        sortable: 'custom',
        formatter: formatDateTime,
        formFieldItemType: 'datetime',
        width: 250,
    },

    {
        ...tableColumnDefault,
        order: 6,
        prop: 'free_days',
        label: '免堆期',
        sortable: 'custom',
        width: 200,
    },

    {
        ...tableColumnDefault,
        order: 7,
        prop: 'dam_id',
        label: '当前箱况',
        formatter: onFormatter,
        sortable: 'custom',
        formFieldItemType: 'single',
        optionalValues: cntrDam.value,
        width: 100,
    },
    {
        ...tableColumnDefault,
        order: 8,
        prop: 'remark',
        label: '备注',
        sortable: 'custom',
        width: 300,
    },
]);

/* const dialogQueryVisible = ref(false);
let queryWhere = {};
 */
/* const onRefresh = async () => {
    const req = new Request('盘存查询', {
        skip: (currentPage.value - 1) * pageSize.value,
        take: pageSize.value,
        order: orders,
        ...queryWhere,
    });
    const r = await req.post();

    totalnum.value = r.ext;
    tableData.value.length = 0;

    if (!isEmpty(r.obj)) {
        tableData.value = r.obj;
    }
};
const {
    currentPage,
    orders,
    pageSize,
    totalnum,
    handleSizeChange,
    handleCurrentChange,
    handleSortChange,
} = useTableInfo(onRefresh); */
onMounted(() => {
    
});
/* const onCloseDialog = async (arg: any) => {
    if (dialogQueryVisible.value) {
        // 查询
        currentPage.value = 1;
        queryWhere = arg;
        onRefresh();

        dialogQueryVisible.value = false;
    }
}; */
/* const handleCommand = async (command: string | number | object) => {
    if (command === 'current') {
        exportExcel('Inventory-table-cntrs');
    } else {
        const columns = [];
        for (let index = 0; index < tableColumns.length; index++) {
            const element = tableColumns[index];
            columns.push(element.prop);
        }
        const req = new Request('导出盘存查询', {
            // skip: (currentPage.value - 1) * pageSize.value,
            // take: pageSize.value,
            order: orders,
            ...queryWhere,
            excelColumn: columns,
        });
        const r = await req.post();
        if (!isEmpty(r.obj)) {
            // tableData.value = r.obj;
            // const url = r.obj; // 后端提供的下载接口
            window.open(r.obj, '_blank');
        }
    }
}; */

/* const onQuery = () => {
    dialogQueryVisible.value = true;
}; */
const queryItems: Array<QueryItem> = pickQueryFromTable(tableColumns);
</script>
<style lang="scss" scoped>
.bg {
    margin-top: 10px;

    .btn {
        margin-right: 10px;
    }
}

.page {
    float: right;
    margin-top: 10px;
}
</style>
